package com.junchenrobot.mes.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 异步线程池配置
 *
 * @author SeaWave
 * @date 2022/10/21
 */
public class AsyncExecutorConfig {

    /**
     * 核心池数
     */
    @Value("${async.corePoolSize}")
    private Integer corePoolSize;

    /**
     * 最大池数
     */
    @Value("${async.maxPoolSize}")
    private Integer maxPoolSize;

    /**
     * 队列容量
     */
    @Value("${async.queueCapacity}")
    private Integer queueCapacity;

    /**
     * 线程前缀名称
     */
    @Value("${async.threadNamePrefix}")
    private String threadNamePrefix;

    /**
     * 是否守护进程
     */
    @Value("${async.daemon}")
    private Boolean daemon;

    /**
     * 存活时间
     */
    @Value("${async.keepAliveSeconds}")
    private Integer keepAliveSeconds;


    /**
     * 配置异步线程池
     *
     * @return {@link ThreadPoolTaskExecutor}
     */
    //public ThreadPoolTaskExecutor configAsyncThreadPool() {
    //    ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
    //    threadPoolTaskExecutor.setCorePoolSize(corePoolSize);
    //    threadPoolTaskExecutor.setMaxPoolSize(maxPoolSize);
    //    threadPoolTaskExecutor.setKeepAliveSeconds(keepAliveSeconds);
    //    threadPoolTaskExecutor.setQueueCapacity(queueCapacity);
    //    threadPoolTaskExecutor.setThreadNamePrefix(threadNamePrefix);
    //    // 拒绝策略 抛出异常
    //    threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
    //    threadPoolTaskExecutor.setDaemon(daemon);
    //    threadPoolTaskExecutor.initialize();
    //    return threadPoolTaskExecutor;
    //}

}
